package com.gugee.ins.common.dal.mapper.statistics;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gugee.ins.common.model.mysql.statistics.InsStProductBase;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * ins商品统计表 Mapper 接口
 * </p>
 *
 * @author HuangXin
 * @since 2021-02-25
 */
public interface InsStProductBaseMapper extends BaseMapper<InsStProductBase> {
    /**
     * 根据productId查找
     * @param productId
     * @param type
     * @return
     */
    @Select("select * from ins_st_product_base where product_id = #{productId} and date_type = #{type}")
    InsStProductBase findByProductIdAndType(long productId,int type);

    /**
     * 根据productId 和 限制时间 生成统计值结果
     * @param productId
     * @param limitTime
     * @return
     */
    @Select("select count(1) media_count,IFNULL(sum(t2.comment_count) + sum(t2.like_count),0) tec," +
            " count(distinct t2.owner_uid) influencer_count from " +
            " (select shortcode from ins_rel_media_product where product_id = #{productId} and taken_time > #{limitTime} )t1 " +
            " inner join ins_media t2 " +
            " on t1.shortcode = t2.shortcode")
    InsStProductBase findStResultByProductId(long productId, long limitTime);
}
